﻿<!DOCTYPE>
<html ng-app="updpwdApp">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, width=device-width, minimal-ui">
    <link href="/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/css/pensonel.css" />
     <script src="/framework/angular-wang-editor/dist/js/lib/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="/framework/angular.min.js"></script>
    <title ng-bind="'重置密码-'+systemTitle"></title>
</head>
<body>
    <!-- 注册第一步-->
    <section class="content">
 
<div class="signup"  ng-controller="updpwdCtrl" ng-cloak>

<div class="formsignup">
<div class="form-unit">


    <form class="new_password" name="myForm2" novalidate ng-show="!repSuccessFlag">
        <div class="topsigunp"><img ng-src="{{orginfo.organization_mainlogo}}" src="/images/logo.png" onerror="javascript:this.src='/images/logo.png'" alt=""  style="max-width: 256px;max-height: 80px;" ></div>
          <div class="info-field">
            <div class="form_title">更新密码</div>

          </div>
		   <div class="form-field">
                <input type="password" name="oldpwd" id="oldpwd" placeholder="请输入旧的密码" autocomplete="off" class="form-control password"  ng-model="oldpwd" required  set-focus ng-focus  />
            </div>
          <div class="form-field">
                <input type="password" name="password" id="password" placeholder="请输入新的密码" autocomplete="off" class="form-control password"  ng-model="password" required ng-minlength="6" ng-maxlength="16" required ng-focus  />
            </div>
            
            <div class="form-field">
                <input type="password" name="password_new" id="password_new" placeholder="请输入确认密码" autocomplete="off" class="form-control password"  ng-model="password_new"  ng-minlength="6" ng-maxlength="16" equals="password" required ng-focus />
            </div>

          <div class="form-fidld errormsg" ng-show="myForm2.password.$dirty && (myForm2.password.$invalid ||myForm2.password.$error.minlength || myForm2.password.$error.maxlength)&& !myForm2.password.$focused">                
                <span ng-show="myForm2.password.$dirty && (myForm2.password.$invalid ||myForm2.password.$error.minlength || myForm2.password.$error.maxlength)&& !myForm2.password.$focused">密码不能为空，并且为6-16位字母、数字</span>          
           </div>

          <div class="form-fidld errormsg" ng-show="myForm2.password_new.$dirty && (myForm2.password_new.$invalid ||myForm2.password_new.$error.minlength || myForm2.password_new.$error.maxlength)&& !myForm2.password_new.$focused">                
                <span ng-show="myForm2.password_new.$dirty && (myForm2.password_new.$invalid ||myForm2.password_new.$error.minlength || myForm2.password_new.$error.maxlength)&& !myForm2.password_new.$focused">密码不能为空，并且为6-16位字母、数字</span>          
           </div>

           <div class="form-fidld errormsg" ng-show="pwddiff">                
                <span ng-show="pwddiff">两次密码不一致</span>          
           </div>

           <div class="form-fidld errormsg" ng-show="unerr">
				<span ng-show="unerr">{{unerr_msg}}</span>
           </div>
           
           <button type="submit" class="btn form_btn submit"  ng-click="updpwd()"  ng-disabled="myForm2.$invalid">重置密码</button>
    </form>
    <!-- 修改成功 -->
    <form class="login-was-successful" ng-show ="repSuccessFlag">
				<div class="topsigunp"><img ng-src="{{orginfo.organization_mainlogo}}" src="/images/logo.png" onerror="javascript:this.src='/images/logo.png'" alt=""></div>
				<div class="login-successful-img"><i class="iconfont">&#xe602;</i></div>
        <div class="form-field"><div class="form_title">密码修改成功！请您注意！
        <br/><span class="form_title_yx">{{username}}</span><br/> 
        <!--<span>5</span>秒自动登录，如页面未加载请点击下方按钮。-->
        </div></div>
         <button type="submit" class="btn form_btn submit" ng-click="ljlogin()" >重新登录</button>

    </form>
</div>
</div>
</div>

</section>
    <script src="/framework/lodash.min.js" type="text/javascript"></script>
    <script src="/framework/restangular/restangular.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/framework/angular-toastr/angular-toastr.min.js"></script>
    <script type="text/javascript" src="/framework/angular-toastr/angular-toastr.tpls.min.js"></script>
    <script src="/system/service/common.js" type="text/javascript"></script>
    <script type="text/javascript">
        var mainApp = angular.module("updpwdApp", ['Common']).config(['toastrConfig', '$locationProvider', function (toastrConfig, $locationProvider) {
            $locationProvider.html5Mode({
                enabled: true,
                requireBase: false//必须配置为false，否则<base href=''>这种格式带base连接的地址才能解析
            });
        } ]);

        mainApp.directive('setFocus', function () {
            return function (scope, element) {
                element[0].focus();
            };
        });

        mainApp.directive('ngFocus', function () {
            //var FOCUS_CLASS = "ng-focused";
            return {
                restrict: 'A',
                require: 'ngModel',
                link: function (scope, element, attrs, ctrl) {
                    ctrl.$focused = true;
                    element.bind('focus', function (evt) {
                        //element.addClass(FOCUS_CLASS);
                        scope.$apply(function () {
                            ctrl.$focused = true;
                        });
                    }).bind('blur', function () {
                        //element.removeClass(FOCUS_CLASS);
                        scope.$apply(function () {
                            ctrl.$focused = false;
                        })
                    })
                }
            }
        });

        mainApp.controller('updpwdCtrl', ['$scope', 'RequestUserService', '$location', 'sysUserInfo', 'Msg', 'Restangular', function ($scope, RM, $location, sysUserInfo, Msg, Restangular) {
            //            console.log("userid:" + $location.search().userid);
            $scope.pwddiff = false;
            $scope.repSuccessFlag = false;
            Restangular.addFullRequestInterceptor(function (element, operation, route, url, headers, params, httpConfig) {
                //这个地方需要把登录得到的token写入到请求数据的头文件中
                var usertoken = sysUserInfo.getuserinfotoken().toString();
                if (usertoken == undefined || usertoken == null || usertoken == "") {
                    return;
                }
                return {
                    headers: { "X-Session-Token": usertoken, "Content-Type": "application/x-www-form-urlencoded;charset=utf-8" }
                };
            });
            $scope.updpwd = function () {
                if ($scope.password != $scope.password_new) {
                    $scope.pwddiff = true;
                } else {
                    var user_id = JSON.parse(localStorage.getItem("userinfo")); // $location.search().userid;
                    if (user_id == undefined || user_id == null || user_id == "") {
                        if (sysUserInfo.getuserinfo() == null) {
                            Msg.warning("用户信息验证有误，请稍后重试！")
                            window.location.href = "/login.html";
                        } else {
                            user_id = sysUserInfo.getuserinfo().user_ID;
                            $scope.systemTitle = sysUserInfo.getuserinfo().organization_Name;
                        }
                    } else {
                        user_id = user_id.user_ID;
                    }
                    //Restangular.one("/ApiUser/").customPOST({ name: "My Message" }, "updatePwd",
                    RM.updatePwd({ userid: user_id, userpwd: hex_md5($scope.password).toUpperCase(), oldpwd: hex_md5($scope.oldpwd).toUpperCase() }).then(function (retData) {
                        //console.log(retData);
                        if (retData.errorcode == "0") {
                            $scope.repSuccessFlag = true;
                            sysUserInfo.setuserinfo(null);
                            Msg.success("密码修改成功，请重新登录！");
                        } else {
                            $scope.unerr = true;
                            if (retData.errorcode == "1") { $scope.unerr_msg = "修改失败！"; }
                            else if (retData.errorcode == "5") { $scope.unerr_msg = "连接不上服务器！"; }
                            else if (retData.errorcode == "6") { $scope.unerr_msg = "系统内部错误！"; }
							else if (retData.errorcode == "12") { $scope.unerr_msg = "旧密码错误！"; }
                        }
                    }, function errorCallback() {
                        $scope.unerr = true;
                        $scope.unerr_msg = "连接服务器失败！";
                    });
                }
            }
            //立即登录
            $scope.ljlogin = function () {
                window.location.href = "/login.html";
            }
        } ]);
    </script>
    <script src="/framework/md5.js" type="text/javascript"></script>
    <script src="/system/service/userpathservice.js" type="text/javascript"></script>
</body>
</html>
